﻿#region Librerias
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
#endregion

/// <summary>
/// Class Person, agrupa a las clases dependientes natural y legal
/// </summary>

#region Class

public class clsPerson : DAC
{
    #region Variables

    private int idPerson, iflgTypePerson;
    private const String tabla = "dbo.tblPerson";
        
    #endregion    

    #region Builder

    /// <summary>
    /// Constructor
    /// </summary>
    public clsPerson() { }

    #endregion

    #region Methods

    #region Consultations

    public DataSet SeeAllTheRecords()
    {
        String query = "SELECT row_number() over(order by " + tabla + ".idPerson) As NUMBER, ";
               query += tabla + ".idPerson As ID, " + tabla + ".iflgTypePerson As FLAG ";
               query += " FROM " + tabla;
        return this.ExecuteQuery(query);
    }
    
    public DataSet ConsultID(String id)
    {
        String query = "SELECT row_number() over(order by " + tabla + ".idPerson) As NUMBER, ";
               query += tabla + ".idPerson As ID, " + tabla + ".iflgTypePerson As FLAG ";
               query += "FROM " + tabla;
               query += " WHERE " + tabla + ".idPerson =" + id;
        return this.ExecuteQuery(query);
    }

    #endregion

    public int Insert()
    {
        String query = "INSERT INTO " + tabla;
                query += "(iflgTypePerson)";
                query += "VALUES ('{0}') SELECT CAST(scope_identity() AS int)";

        String sql = String.Format(query,this.IFlgTypePerson);
        return this.ExecuteDML(sql, "yes");
    }

    public int Update()
    {
        String query = "UPDATE " + tabla + " SET ";
        query += tabla + ".iflgTypePerson=" + this.IFlgTypePerson;
        query += " WHERE ";
        query += tabla + ".idPerson=" + this.ID;
        return this.ExecuteDML(query, "no");
    }

    public int Delete()
    {
        String query = "DELETE FROM " + tabla + " WHERE " + tabla + ".idPerson={0}";
        String sql = String.Format(query, this.ID);
        return this.ExecuteDML(sql, "no");
    }

    #endregion

    #region Setters and Getters

    public int IFlgTypePerson
    {
        get { return iflgTypePerson; }
        set { iflgTypePerson = value; }
    }

    public int ID
    {
        get { return idPerson; }
        set { idPerson = value; }
    }

    #endregion

}

#endregion


